<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>滴答办公系统-班级新增</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="media/layui/css/layui.css" media="all">
<script type="text/javascript" src="media/js/jquery.min.js"></script>
<script type="text/javascript" src="media/js/jquery.md5.js"></script>
</head>
<body>
	<div class="layui-container" style="margin-top: 5px">
		<form class="layui-form" action="gradeadd.do" method="post">
			<div class="layui-form-item">
				<label class="layui-form-label">原始密码</label>
				<div class="layui-input-block">
					<input type="text" id="oldPass" name="name" lay-verify="name" autocomplete="off"
						placeholder="请输入密码" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">新密码</label>
				<div class="layui-input-block">
				 <input type="password" id="newPass" name="password" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">确认新密码</label>
				<div class="layui-input-block">
			      <input type="password" id="newPassVerify" name="password" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<input class="layui-btn"  style="margin-left: 10%" onclick="modUserPassword()" value="确认修改">
			</div>
		</form>
	</div>


	<script src="media/layui/layui.js"></script>
	<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
	<script>
	var form;
		layui.use([ 'form', 'laydate' ],
				function() {
				form = layui.form, layer = layui.layer, laydate = layui.laydate;
						//日期
						laydate.render({
							elem : '#date'
						});
		});
    
    function getQueryVariable(variable) {
      var query = window.location.search.substring(1);
      var vars = query.split("&");
      for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) {
          return pair[1];
        }
      }
      return (false);
    }
    
    function modUserPassword() {
      var oldPass = $('#oldPass').val();
      var newPass = $('#newPass').val();
      var newPassVerify = $('#newPassVerify').val();
      if($.md5(oldPass) != getQueryVariable("pass")) {
        alert("旧密码输入错误！");
      }else if(newPass != newPassVerify) {
        alert("两次新密码输入不匹配！");
      }else{
        $.ajax({
          url: "/emp/emp/modEmp",
          type: "POST",
          dataType: "json",
          data: {
            id: getQueryVariable("id"),
            pass: newPass
          },
          success: function(data) {
            var index = parent.layer.getFrameIndex(window.name);
            //关闭当前frame
            parent.layer.close(index);
            window.parent.location.reload();
          },
          error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest.status);
            alert(XMLHttpRequest.readyState);
            alert(textStatus);
          }
        });
      }
    }
		
	</script>
</body>
</html>